package cn.blbsz.shop.service.impl;

import cn.blbsz.shop.domain.p.UserSigninRepository;
import cn.blbsz.shop.service.UserSigninService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.Date;

/**
 * Created by yipingdong on 2017/4/13.
 */
@Service
public class UserSigninServiceImpl implements UserSigninService {

    @PersistenceContext(name = "entityManagerPrimary")
    private EntityManager entityManager;

    @Autowired
    private UserSigninRepository userSigninRepository;

    @Override
    public String findSigninInfo(Long userId, Date date) {
        return String.valueOf(entityManager.createNativeQuery("{call p_user_signin_info(?,?)}")
                .setParameter(1,userId)
                .setParameter(2,date).getSingleResult());
    }

    @Override
    public String signin(Long userId, Date date) {
        return String.valueOf(entityManager.createNativeQuery("{call p_user_signin(?,?)}")
                .setParameter(1,userId)
                .setParameter(2,date).getSingleResult());
    }
}
